﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace DBSchemaViewer.BackEnd.Entities
{
    public class EntityTable : EntityBase
    {        
        public Point CanvasCoordinates {get;set;}
        
        public string Name { get; set; }

        public ObservableCollection<EntityTableFieldEntry> Fields { get; set; }


        /// <summary>
        /// Returns a copy of the entity (by using this we can just work with the copied entity without affecting
        /// the original one and relations fields list).
        /// </summary>
        /// <returns></returns>
        public EntityTable Copy()
        {
            EntityTable copiedTable = new EntityTable();
            copiedTable.InternalID = this.InternalID;
            copiedTable.CanvasCoordinates = this.CanvasCoordinates;
            copiedTable.Name = this.Name;

            copiedTable.Fields = new ObservableCollection<EntityTableFieldEntry>();

            foreach (EntityTableFieldEntry currentField in Fields)
            {
                EntityTableFieldEntry newEntry = new EntityTableFieldEntry();

                newEntry.InternalID = currentField.InternalID;
                newEntry.IsPrimaryKey = currentField.IsPrimaryKey;
                newEntry.IsForeignKey = currentField.IsForeignKey;
                newEntry.FieldName  = currentField.FieldName;
                newEntry.Type  = currentField.Type;
                newEntry.Length = currentField.Length;

                copiedTable.Fields.Add(newEntry);
            }

            return copiedTable;
        }

    }
}
